<template>
    <el-checkbox v-bind="$attrs" :disabled="disabled" v-model="val" :label="label"></el-checkbox>
</template>

<script>


export default {
    name: "MyCheckBox",
    inject: {
        CheckAll: { default: null },
    },
    emits: ["update:modelValue"],
    props: {
        label: String,
        modelValue: [Boolean, String],
        disabled: Boolean
    },
    mounted() {
        if (this.CheckAll) {
            this.CheckAll.addItem(this);
        }
    },
    unmounted() {
        if (this.CheckAll) {
            this.CheckAll.removeItem(this);
        }
    },
    methods: {
        doCheckAll(checked) {
            if (!this.disabled) {
                this.$emit('update:modelValue', checked);
            }
        }
    },
    computed: {
        val: {
            get() {
                return this.modelValue;
            },
            set(newVal) {
                this.$emit("update:modelValue", newVal);
            }
        }
    }
}
</script>